/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.a.web;

import javax.annotation.Resource;
import javax.print.attribute.standard.PresentationDirection;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.method.P;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.modules.a.entity.TestGoods2;
import com.thinkgem.jeesite.modules.a.service.TestGoods2Service;

/**
 * 测试商品表Controller
 * @author dby
 * @version 2020-09-07
 */
@Controller
@RequestMapping(value = "${adminPath}/a/testGoods2")
public class TestGoods2Controller extends BaseController {

	@Autowired
	public TestGoods2Service testGoods2Service;

	@ModelAttribute
	public TestGoods2 get(@RequestParam(required=false) String id){
		TestGoods2 entity=null;
		if(StringUtils.isNotBlank(id)){
			entity=testGoods2Service.get(id);
		}
		if(entity==null){
			entity=new TestGoods2();
		}
		return entity;
	}

	@RequiresPermissions("a:testGoods2:view")
	@RequestMapping(value = {"list",""})
	public String list(TestGoods2 testGoods2,HttpServletRequest request,HttpServletResponse response,Model model){
		Page<TestGoods2> page =testGoods2Service.findPage(new Page<TestGoods2>(request,response),testGoods2);
		model.addAttribute("page",page);
		return "modules/a/testGoods2List";
	}

	@RequiresPermissions("a:testGoods2:view")
	@RequestMapping(value="form")
	public String form(TestGoods2 testGoods2,Model model){
		model.addAttribute(testGoods2);
		return "modules/a/testGoods2Form";
	}

	@RequiresPermissions("a:testGoods2:edit")
	@RequestMapping(value = "save")
	public String save(TestGoods2 testGoods2,RedirectAttributes redirectAttributes,Model model){
		if(!beanValidator(model,testGoods2)){
			return form(testGoods2,model);
		}
		testGoods2Service.save(testGoods2);
		addMessage(redirectAttributes,"保存商品订单成功");
		return "redirect:"+Global.getAdminPath()+"/a/testGoods2/?repage";
	}

	@RequiresPermissions("a:testGoods2:edit")
	@RequestMapping(value ="delete")
	public String delete(TestGoods2 testGoods2,RedirectAttributes redirectAttributes){
		testGoods2Service.delete(testGoods2);
		addMessage(redirectAttributes,"删除商品订单成功");
		return "redirect:"+Global.getAdminPath()+"/a/testGoods2/?repage";
	}
	
}
